﻿using Core.Configuration.Api;
using IconYuan.Manager.Products;
using IconYuan.Model.DTO.Products;
using IconYuan.Model.Products;
using Microsoft.AspNetCore.Mvc;

namespace IconYuan.Api.Controllers.Admin.Products
{
    public class GoodsController : AdminApi
    {
        GoodsManager goodsSvc;
        public GoodsController()
        {
            goodsSvc = new GoodsManager();
        }

        [HttpPost]
        //public async Task<bool> Add([FromBody] GoodsAddDto model)
        public async Task<bool> Add([FromBody] Goods model)
        {
            var goods = model as Goods;
            goods.update_time = DateTime.Now;
            goods.store_id = store_id;

            if (goods.goods_id > 0)
            {
                return await goodsSvc.UpdateAsync(goods);
            }
            else
            {
                goods.create_time = DateTime.Now;
                var count = await goodsSvc.InsertAsync(goods);
                return count > 0;
            }

        }
    }
}
